package com.ecsolutions.controller;

import com.ecsolutions.entity.BaseEntity;
import com.ecsolutions.entity.asset.DepositEntity;
import com.ecsolutions.entity.asset.DepositTypeEntity;
import com.ecsolutions.service.asset.DepositService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2017/5/17.
 */
@RestController
@RequestMapping("/account")
public class AccountBalanceController {
    @Autowired
    private DepositService depositService;

    public DepositService getDepositService() {
        return depositService;
    }

    @CrossOrigin(origins = "*")
    @GetMapping("/{customer_code}")
    public BaseEntity getAccount(@PathVariable("customer_code") String customer_code) {
        BaseEntity ret = new BaseEntity();
        try {
            DepositEntity depositEntity = this.depositService.getAssets(customer_code);
            ret.setData(depositEntity);

            ret.setCode(200);
            ret.setMsg("success");
        } catch (Exception ex) {
            ret.setCode(-1);
            ret.setMsg("get overview failed!");
        }
        return ret;
    }

    @CrossOrigin(origins = "*")
    @GetMapping("/getNatureAccounts")
    public BaseEntity getNatureAccounts(@RequestParam("customer_code") String customer_code, @RequestParam("nature") String nature) {
        BaseEntity ret = new BaseEntity();
        try {
            List<DepositTypeEntity> depositTypeEntities = this.depositService.getNatureAccounts(customer_code, nature);
            ret.setData(depositTypeEntities);
            ret.setCode(200);
            ret.setMsg("success");
        } catch (Exception ex) {
            ret.setCode(-1);
            ret.setMsg("get overview failed!");
        }
        return ret;
    }

}
